<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/view/common/header-talent.jspf"%>
<div class="container">
	<center>
		<h1>个人简历信息</h1>
	</center>
	<span class="pull-right"> 
	<div class="btn-group ">
	<a href="<%=request.getContextPath()%>/view/talent/resume-add.jsp" class="btn btn-info " style="right:976px;">添加简历</a>
	<a href="javascript:deleteResume(${resume.id })" class="btn btn-warning">点击删除</a>
	</div>
	</span>
	<center><span class="label label-danger">${error }</span></center>
	<table class="table table-hover table-bordered">
	<thead>
		<tr class="info">
			<th>序 号</th>
			<th>求职意向</th>
			<th>工作经验</th>
			<th>项目经历</th>
			<th><input type="checkbox" id="btn1">全选</th>
		</tr>
		</thead>
		<tbody>
		<!--  foreach  展示个人简历信息 -->
		<c:forEach items="${requestScope.resumeList }" var="resume"
			varStatus="v">
			<tr>
				<td>${v.count}</td>
				<td><a
					href="<%=request.getContextPath()%>/ResumeServlet?command=preUpdate&resumeId=${resume.id }">${resume.intention}</a></td>
				<td>${resume.workExperience}</td>
				<td>${resume.projectExperience}</td>
				<td>
					<input type="checkbox"  value="${resume.id}" name="deleteIds" />
				</td>
			</tr>
		</c:forEach>
		<c:if test="${empty requestScope.resumeList  }">
			<tr>
				<td colspan="6" align="center" class="alert alert-danger"
					role="alert">没有数据呢 亲！</td>
			</tr>
		</c:if>
		</tbody>
	</table>
	<center>
		<h1>申请结果</h1>
	</center>
	<table class="table table-hover table-bordered ">
	<thead>
		<tr class="info">
			<th>序 号</th>
			<th>职位名称</th>
			<th>所属企业</th>
			<th>申请状态</th>
			<th>申请时间</th>
			<th>操 作</th>
		</tr>
		</thead>
		<tbody>
		<c:forEach items="${pageModel.list }" var="app" varStatus="v">
			<tr>
				<td>${(pageModel.pageNum - 1) * pageModel.pageSum +v.count}</td>
				<td>${app.positionName }</td>
				<td>${app.companyName}</td>
				<td>${app.statusStr}</td>
				<td>${app.appTime}</td>
				<td><a onclick="deleteApplication(this,${app.id });">删除</a></td>
			</tr>
		</c:forEach>
		<c:if test="${empty pageModel.list }">
			<tr>
				<td colspan="6" align="center" class="alert alert-danger"
					role="alert">没有数据呢 亲！</td>
			</tr>
		</c:if>
		<tr class="active">
			<td colspan="6" align="right">
			<c:choose>
			<c:when test="${pageModel.totalPages <= 10 }">
				<c:set var="begin" value="1" />
				<c:set var="end" value="${pageModel.totalPages }" />
			</c:when>
			<c:otherwise>
			<%-- 当总页数>10时，通过公式计算出begin和end --%>
			<c:set var="begin" value="${pageModel.pageNum-5 }" />
				<c:set var="end" value="${pageModel.pageNum+4 }" /> 
				<c:if test="${begin < 1 }">
				<c:set var="begin" value="1" />
				<c:set var="end" value="10" />
				</c:if> 
				<c:if test="${end > pageModel.totalPages }">
				<c:set var="begin" value="${pageModel.totalPages - 9 }" />
				<c:set var="end" value="${pageModel.totalPages }" />
				</c:if> 
				</c:otherwise>
					</c:choose>
			<%-- 循环遍历页码列表 --%>
			<nav><ul class="pagination">
			 <li <c:if test="${pageModel.pageNum eq 1}"> class="disabled"</c:if>><a href="<%=request.getContextPath()%>/TalentServlet?command=main&pageNum=1"><span>-&infin;</span></a></li>
			 <li <c:if test="${pageModel.pageNum eq 1}"> class="disabled"</c:if>><a href="<%=request.getContextPath()%>/TalentServlet?command=main&pageNum=${pageModel.pageNum-1}"><span>&laquo;</span></a></li>
			<c:forEach var="i" begin="${begin }" end="${end }">
    		 <li <c:if test="${pageModel.pageNum eq i}">class="active" </c:if>><a href="<%=request.getContextPath()%>/TalentServlet?command=main&pageNum=${i }">${i } <span class="sr-only">(current)</span></a></li>
			</c:forEach>	
			 <li <c:if test="${pageModel.pageNum eq pageModel.totalPages}"> class="disabled"</c:if>><a
						href="<%=request.getContextPath()%>/TalentServlet?command=main&pageNum=${pageModel.pageNum+1}"><span>&raquo;</span></a></li>
			 <li <c:if test="${pageModel.pageNum eq pageModel.totalPages}"> class="disabled"</c:if>><a
				href="<%=request.getContextPath()%>/TalentServlet?command=main&pageNum=${pageModel.totalPages}"><span>+&infin;</span></a></li>
			 <li><a>共${pageModel.totalRecords}条记录</a></li>
			</ul>
			</nav>
			</td>
			</tr>
			</tbody>
			</table>
</div>
<script>


	$("#btn1").click( 
  function(){ 
    if(this.checked){ 
        $("input[name='deleteIds']").prop('checked', true)
    }else{ 
        $("input[name='deleteIds']").prop('checked', false)
    } 
  } 
);
	function deleteApplication(obj,appId){
		layer.confirm('确认删除？', {
		    btn: ['确认','取消'] //按钮
		}, function(){
	$.get('<%=request.getContextPath()%>/ApplicationServlet?command=deleteApplication&applicationId='+ appId, function(text){
	     // 如果是成功了就在页面上删除当前a标签所在的tr，如果不成功给出提示
	     if (text == 'fail') {
	    	layer.msg('操作失败！', {time: 2000, icon: 5});
	     } else {
	    	layer.msg('操作成功！', {time: 2000, icon: 6});
	    	$(obj.parentNode.parentNode).remove();
	     }
	  });
		});
	}


	
	function deleteResume() {
		var box = document.getElementsByName("deleteIds");
		if(box.length==0){
			layer.msg('请选中简历');
			return;
		}
			 var resumeIds="";  
			   $("input[name='deleteIds']").each(function() {  
		          if ($(this).prop("checked")) {  
		        	  resumeIds +=$(this).val() +",";  
		        }  
		      });  
		layer.confirm('确认删除？', {
		    btn: ['确认','取消'] //按钮
		}, function(){
			 location = '<%=request.getContextPath()%>/ResumeServlet?command=deleteByIds&resumeIds='
					+ resumeIds;
							});
}
	if('${param.result}' === '0'){
		layer.msg('新增成功',{icon:1});
	}
	function goPage(){
		var page  = document.getElementById("page").value;
		location='<%=request.getContextPath()%>/TalentServlet?command=main&pageNum='
				+ page;
	}
</script>
</body>
</html>